<!--附件弹窗-->
<script setup>

import GlobalDialog from "@/components/common/dialog/GlobalDialog.vue";
import Attachment from "@/components/post/attachment/Attachment.vue";
import {ElementUtils} from "@/assets/js/ElementUtils";
import useClipboard from 'vue-clipboard3'

const {toClipboard} = useClipboard()
// 弹窗名称
const name = 'attachment'

const copyText = async (text) => {
  try {
    await toClipboard(text + '')
    ElementUtils.notice({
      message: "复制成功",
    })
  } catch (e) {
    ElementUtils.notice({
      message: "复制失败",
      type: "warning",
    })
    console.warn(e)
  }
}
</script>

<template>
  <global-dialog :name="name">
    <template #default="{data}">
      <template v-for="({view},index) in data">
        <attachment :data="view" :index="index" @insert="copyText"/>
      </template>
    </template>
    <template #header="{data}">
      <h4 style="margin-top: 0;margin-bottom: 0">附件列表</h4>
    </template>
  </global-dialog>
</template>

<style scoped>
h4 {
  margin-top: 5px;
  margin-bottom: 5px;
}
</style>